extends NodeState


@export var enemy: BasicEnemy

var velocity: Vector2 = Vector2.ZERO
var height: float = 0.0
var height_speed: float = 0.0


func _on_process(delta : float) -> void:
	if _changing_state:
		return
	enemy.position += velocity * delta
	process_animation()
	process_height(delta)


func _on_enter() -> void:
	velocity = Vector2.ZERO
	height = enemy.spawn_drop_height
	enemy.set_collision_disabled(true)


func _on_exit() -> void:
	enemy.set_collision_disabled(false)



func process_animation():
	enemy.animationPlayer.play(BasicEnemy.ANIMATION_DROP)


func process_height(delta: float):
	enemy.characterSprite.position = Vector2.UP * height

	height += height_speed * delta
	# 高度降为0时进入倒地状态
	if height < 0.0:
		height = 0.0
		velocity = Vector2.ZERO
		enemy.characterSprite.position = Vector2.ZERO
		transition_state(BasicEnemy.STATE_LAND)
	else:
		height_speed -= enemy.gravity * delta
